package com.qn;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class TreeNode<T> {
    private Integer id;
    private Integer parentId;
    private List<T> children;
    private Integer index;

    public TreeNode(Integer id, Integer parentId) {
        this.id = id;
        this.parentId = parentId;
        this.children = new ArrayList<>();
        this.index = 1; // 初始化为1表示未设置序号
    }

    public void addChild(T child) {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        this.children.add(child);
    }
}